package cn.app.BaseCode.service.impl;

import cn.app.BaseCode.mapper.BaseCrudMapper;
import cn.app.BaseCode.service.BaseCrudService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public abstract class BaseCrudServiceImpl<M extends BaseCrudMapper<T>, T> implements BaseCrudService<T> {

    @Autowired
    protected M baseCrudMapper;

    @Override
    public T getById(Serializable id) {
        return baseCrudMapper.selectOneById(id);
    }

    @Override
    public List<T> list() {
        return baseCrudMapper.selectAll();
    }

    @Override
    public boolean save(T entity) {
        return baseCrudMapper.insert(entity) > 0;
    }

    @Override
    public boolean update(T entity) {
        return baseCrudMapper.update(entity) > 0;
    }

    @Override
    public boolean removeById(Serializable id) {
        return baseCrudMapper.deleteById(id) > 0;
    }
}
